/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@media (forced-colors: active) {
    :host([focused]) .spectrum-Table-checkbox .spectrum-Checkbox-box:before,
    :host(:focus-visible) .spectrum-Table-checkbox .spectrum-Checkbox-box:before {
        outline: var(--highcontrast-table-row-text-color-hover) 1px solid;
    }

    @media (hover: hover) {
        :host(:hover) .spectrum-Table-checkbox .spectrum-Checkbox-box:before {
            outline: var(--highcontrast-table-row-text-color-hover) 1px solid;
        }
    }

    :host([drop-target]) .spectrum-Table-body,
    :host([drop-target]),
    :host([selected]) {
        --highcontrast-table-cell-focus-indicator-color: var(--highcontrast-table-selected-row-text-color);
        --highcontrast-table-cell-focus-extra-offset: 1px;
    }

    :host([drop-target]) .spectrum-Table-body .spectrum-Table-checkbox .spectrum-Checkbox-box:before,
    :host([drop-target]) .spectrum-Table-checkbox .spectrum-Checkbox-box:before,
    :host([selected]) .spectrum-Table-checkbox .spectrum-Checkbox-box:before {
        outline: var(--highcontrast-table-selected-row-text-color) 1px solid;
    }
}

:host(:first-child) .spectrum-Table-body ::slotted(*) {
    border-block-start: var(--mod-table-border-width, var(--spectrum-table-border-width)) solid var(--highcontrast-table-border-color, var(--mod-table-border-color, var(--spectrum-table-border-color)));
}

:host(:last-child) .spectrum-Table-body ::slotted(*) {
    border-block-end: var(--mod-table-border-width, var(--spectrum-table-border-width)) solid var(--highcontrast-table-border-color, var(--mod-table-border-color, var(--spectrum-table-border-color)));
}

:host .spectrum-Table-body ::slotted(:first-child) {
    border-inline-start: var(--mod-table-outer-border-inline-width, var(--spectrum-table-outer-border-inline-width)) solid var(--highcontrast-table-border-color, var(--mod-table-border-color, var(--spectrum-table-border-color)));
}

:host .spectrum-Table-body ::slotted(:last-child) {
    border-inline-end: var(--mod-table-outer-border-inline-width, var(--spectrum-table-outer-border-inline-width)) solid var(--highcontrast-table-border-color, var(--mod-table-border-color, var(--spectrum-table-border-color)));
}

:host {
    transition: background-color var(--highcontrast-table-transition-duration, var(--mod-table-transition-duration, var(--spectrum-table-transition-duration))) ease-in-out;
    cursor: pointer;
    cursor: var(--mod-table-cursor-row-default, pointer);
    border-block-start: none;
    position: relative;
}

:host(:first-child) ::slotted(:first-child) {
    border-start-start-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:first-child) ::slotted(:last-child) {
    border-start-end-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:last-child) ::slotted(:first-child) {
    border-end-start-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:last-child) ::slotted(:last-child) {
    border-end-end-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:first-child) {
    border-start-start-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
    border-start-end-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:last-child) {
    border-end-end-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
    border-end-start-radius: var(--mod-table-border-radius, var(--spectrum-table-border-radius));
}

:host(:focus) {
    outline: 0;
}

:host([focused]),
:host(:focus-visible) {
    --highcontrast-table-row-text-color: var(--highcontrast-table-row-text-color-hover);
    --highcontrast-table-icon-color: var(--highcontrast-table-row-text-color-hover);
    --spectrum-table-cell-background-color: var(--highcontrast-table-row-background-color-hover, var(--mod-table-row-background-color-hover, var(--spectrum-table-row-background-color-hover)));
}

:host:active {
    --highcontrast-table-row-text-color: var(--highcontrast-table-row-text-color-hover);
    --highcontrast-table-icon-color: var(--highcontrast-table-row-text-color-hover);
    --spectrum-table-cell-background-color: var(--highcontrast-table-row-background-color-hover, var(--mod-table-row-active-color, var(--spectrum-table-row-active-color)));
}

:host([selected]) {
    --highcontrast-table-row-text-color: var(--highcontrast-table-selected-row-text-color);
    --highcontrast-table-icon-color: var(--highcontrast-table-selected-row-text-color);
    --spectrum-table-cell-background-color: var(--highcontrast-table-selected-row-background-color, var(--spectrum-table-selected-cell-background-color));
}

:host([selected][focused]),
:host([selected]:focus-visible) {
    --highcontrast-table-row-text-color: var(--highcontrast-table-selected-row-text-color-focus);
    --highcontrast-table-icon-color: var(--highcontrast-table-selected-row-text-color-focus);
    --spectrum-table-cell-background-color: var(--highcontrast-table-selected-row-background-color-focus, var(--spectrum-table-selected-cell-background-color-focus));
}

:host([drop-target]) .spectrum-Table-body,
:host([drop-target]) {
    --highcontrast-table-row-text-color: var(--highcontrast-table-selected-row-text-color);
    --highcontrast-table-icon-color: var(--highcontrast-table-selected-row-text-color);
    --spectrum-table-cell-background-color: var(--highcontrast-table-selected-row-background-color, var(--mod-table-drop-zone-background-color, var(--spectrum-table-drop-zone-background-color)));
}

:host([drop-target]) {
    --mod-table-border-color: var(--highcontrast-table-focus-indicator-color, transparent);
    outline-width: var(--mod-table-focus-indicator-thickness, var(--spectrum-table-focus-indicator-thickness));
    outline-style: solid;
    outline-color: var(--highcontrast-table-focus-indicator-color, var(--mod-table-drop-zone-outline-color, var(--spectrum-table-drop-zone-outline-color)));
    outline-offset: calc(var(--mod-table-focus-indicator-thickness, var(--spectrum-table-focus-indicator-thickness)) * -1);
}

:host([drop-target]) ::slotted(*) {
    border-block-start-color: var(--highcontrast-table-focus-indicator-color, var(--mod-table-drop-zone-outline-color, var(--spectrum-table-drop-zone-outline-color)));
}

.spectrum-Table-row--summary {
    --spectrum-table-cell-background-color: var(--highcontrast-table-row-background-color, var(--mod-table-summary-row-background-color, var(--spectrum-table-summary-row-background-color)));
}

.spectrum-Table-row--summary ::slotted(*) {
    font-weight: var(--mod-table-summary-row-font-weight, var(--spectrum-table-summary-row-font-weight));
    font-size: var(--mod-table-summary-row-font-size, var(--spectrum-table-row-font-size));
    font-family: var(--mod-table-summary-row-font-family, var(--spectrum-table-row-font-family));
    font-style: var(--mod-table-summary-row-font-style, var(--spectrum-table-row-font-style));
    line-height: var(--mod-table-summary-row-line-height, var(--spectrum-table-row-line-height));
    color: var(--highcontrast-table-row-text-color, var(--mod-table-summary-row-text-color, var(--spectrum-table-row-text-color)));
}

.spectrum-Table-row--sectionHeader {
    --spectrum-table-cell-background-color: var(--highcontrast-table-section-header-background-color, var(--mod-table-section-header-background-color, var(--spectrum-table-section-header-background-color)));
    cursor: auto;
    cursor: var(--mod-table-cursor-section-header, initial);
}

.spectrum-Table-row--sectionHeader ::slotted(*) {
    font-weight: var(--mod-table-section-header-font-weight, var(--spectrum-table-section-header-font-weight));
    text-align: start;
    block-size: var(--mod-table-section-header-min-height, var(--spectrum-table-section-header-min-height));
    font-size: var(--mod-table-section-header-font-size, var(--spectrum-table-row-font-size));
    font-family: var(--mod-table-section-header-font-family, var(--spectrum-table-row-font-family));
    font-style: var(--mod-table-section-header-font-style, var(--spectrum-table-row-font-style));
    line-height: var(--mod-table-section-header-line-height, var(--spectrum-table-row-line-height));
    color: var(--highcontrast-table-section-header-text-color, var(--mod-table-section-header-text-color, var(--spectrum-table-row-text-color)));
    padding-block-start: calc(var(--mod-table-section-header-block-start-spacing, var(--spectrum-table-section-header-block-start-spacing)) - var(--mod-table-border-width, var(--spectrum-table-border-width)));
    padding-block-end: calc(var(--mod-table-section-header-block-end-spacing, var(--spectrum-table-section-header-block-end-spacing)) - var(--mod-table-border-width, var(--spectrum-table-border-width)));
}

:host {
    display: table-row;
}

:host(:first-child) .spectrum-Table-scroller .spectrum-Table-body ::slotted(*) {
    border-block-start: none;
    border-radius: 0;
}

:host(:last-child) .spectrum-Table-scroller .spectrum-Table-body ::slotted(*) {
    border-block-end: none;
    border-radius: 0;
}

:host .spectrum-Table-scroller .spectrum-Table-body ::slotted(:first-child) {
    border-inline-start: none;
}

:host .spectrum-Table-scroller .spectrum-Table-body ::slotted(:last-child) {
    border-inline-end: none;
}

.spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 0;
}

:host([data-tier="1"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 1;
}

:host([data-tier="2"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 2;
}

:host([data-tier="3"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 3;
}

:host([data-tier="4"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 4;
}

:host([data-tier="5"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 5;
}

:host([data-tier="6"]) .spectrum-Table-row--collapsible {
    --spectrum-table-row-tier: 6;
}

.spectrum-Table-row--collapsible .spectrum-Table-checkboxCell {
    padding-inline-end: 0;
}

.spectrum-Table-row--collapsible.is-last-tier .spectrum-Table-cell--collapsible {
    padding-inline-start: calc(var(--spectrum-table-row-tier) * var(--spectrum-table-collapsible-tier-indent) + var(--mod-table-disclosure-icon-size, var(--spectrum-table-disclosure-icon-size)) + var(--mod-table-collapsible-disclosure-inline-spacing, var(--spectrum-table-collapsible-disclosure-inline-spacing)) * 2);
}

.spectrum-Table-row--collapsible.is-last-tier .spectrum-Table-disclosureIcon {
    display: none;
}

.spectrum-Table-row--collapsible .spectrum-Table-disclosureIcon {
    margin-inline: var(--mod-table-collapsible-disclosure-inline-spacing, var(--spectrum-table-collapsible-disclosure-inline-spacing));
    margin-block-start: max(0px, calc((var(--mod-table-min-row-height, var(--spectrum-table-min-row-height)) - var(--mod-table-disclosure-icon-size, var(--spectrum-table-disclosure-icon-size))) / 2));
}

:host([hidden]) .spectrum-Table-row--collapsible {
    display: none;
}

@media (hover: hover) {
    :host(:hover) {
        --highcontrast-table-row-text-color: var(--highcontrast-table-row-text-color-hover);
        --highcontrast-table-icon-color: var(--highcontrast-table-row-text-color-hover);
        --spectrum-table-cell-background-color: var(--highcontrast-table-row-background-color-hover, var(--mod-table-row-background-color-hover, var(--spectrum-table-row-background-color-hover)));
    }

    :host([selected]:hover) {
        --highcontrast-table-row-text-color: var(--highcontrast-table-selected-row-text-color-focus);
        --highcontrast-table-icon-color: var(--highcontrast-table-selected-row-text-color-focus);
        --spectrum-table-cell-background-color: var(--highcontrast-table-selected-row-background-color-focus, var(--spectrum-table-selected-cell-background-color-focus));
    }

    .spectrum-Table-row--sectionHeader:hover {
        --highcontrast-table-row-text-color: var(--highcontrast-table-section-header-text-color);
        --spectrum-table-cell-background-color: var(--highcontrast-table-section-header-background-color, var(--mod-table-section-header-background-color, var(--spectrum-table-section-header-background-color)));
    }
}

.spectrum-Table-row--thumbnail {
    --spectrum-table-thumbnail-cell-block-spacing: var(--mod-table-thumbnail-block-spacing, var(--spectrum-table-thumbnail-block-spacing));
    --spectrum-table-thumbnail-inner-content-block-spacing: max(0px, calc((var(--mod-table-thumbnail-size, var(--spectrum-table-thumbnail-size)) - (var(--mod-table-row-line-height, var(--spectrum-table-row-line-height)) * var(--mod-table-header-font-size, var(--spectrum-table-row-font-size)))) / 2));
}

.spectrum-Table-row--thumbnail ::slotted(*) {
    padding-block: calc(var(--spectrum-table-thumbnail-cell-block-spacing) + var(--spectrum-table-thumbnail-inner-content-block-spacing));
}

.spectrum-Table-row--thumbnail .spectrum-Table-cell--thumbnail {
    padding-block: 0;
}

.spectrum-Table-row--thumbnail.spectrum-Table-row--collapsible {
    --spectrum-table-thumbnail-inner-minimum-block-spacing: max(0px, calc((var(--mod-table-disclosure-icon-size, var(--spectrum-table-disclosure-icon-size)) - var(--mod-table-thumbnail-size, var(--spectrum-table-thumbnail-size))) / 2));
    --spectrum-table-thumbnail-cell-block-spacing: max(var(--mod-table-thumbnail-block-spacing, var(--spectrum-table-thumbnail-block-spacing)), var(--spectrum-table-thumbnail-inner-minimum-block-spacing));
}
